package com.sctvcloud.dongqu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.beans.AFileItem;
import com.sctvcloud.dongqu.beans.FProgram;
import com.sctvcloud.dongqu.beans.LiveItem;
import com.sctvcloud.dongqu.beans.NewsItem;
import com.sctvcloud.dongqu.beans.TopicItem;
import com.sctvcloud.dongqu.ui.adapter.holder.AnchorFilesHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.AnchorIntroHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.BaseAnchorHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.BaseSearchReultHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.LiveHomeItemHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchResultAnchorHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchResultArticleconHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchResultArticletiHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchResultLiveHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchResultTopicHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchResultTopicconHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchResultTopictiHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.TopicDetailTopHolder;
import com.sctvcloud.dongqu.ui.util.IListInfoData;
import com.sctvcloud.dongqu.ui.util.IListShowData;

import java.util.List;

/**
 * Created by yuxipan on 2017-01-06.
 */

public class SearchResultAdapter extends BaseHolderAbsAdapter<IListShowData, BaseSearchReultHolder<IListShowData>> {
    public static final int VIEWTYPE_TOPIC_TITLE = 6;//包含专题的item标题
    public static final int VIEWTYPE_TOPIC_CONTENT = 7;//包含专题内容的item
    public static final int VIEWTYPE_ARTICLE_TITLE = 8;//包含文章内容item的的标题
    public static final int VIEWTYPE_ARTICLE_CONTENT = 9;//包含文章内容的item

    public static final int NEWS_ITEM = 0;
    public static final int SPECIAL_ITEM = 1;
    public static final int LIVE_ITEM = 2;
    public static final int PROGRAMME_ITEM = 3;
    public static final int ANCHOR_ITEM = 4;
//    private OnItemInternalClick internalClick;


    public SearchResultAdapter(Context context, List<IListShowData> list) {
        super(context, list);

    }

    public void setOnItemInternalClick(OnItemInternalClick internalClick) {
        this.itemInternalClick = internalClick;
    }

    @Override
    public BaseSearchReultHolder<IListShowData> onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseSearchReultHolder holder = null;
        View view = null;
        switch (viewType) {
//            case VIEWTYPE_TOPIC_TITLE:
//                view = LayoutInflater.from(context).inflate(R.layout.item_search_result_topic_title, parent, false);
//                holder = new SearchResultTopictiHolder(context, view);
//                break;
//            case VIEWTYPE_TOPIC_CONTENT:
//                view = LayoutInflater.from(context).inflate(R.layout.item_search_result_topic_content, parent, false);
//                holder = new SearchResultTopicconHolder(context, view);
//                break;
//            case VIEWTYPE_ARTICLE_TITLE:
//                view = LayoutInflater.from(context).inflate(R.layout.item_search_result_article_title, parent, false);
//                holder = new SearchResultArticletiHolder(context, view);
//                break;
//            case VIEWTYPE_ARTICLE_CONTENT:
//                view = LayoutInflater.from(context).inflate(R.layout.item_search_result_article_content, parent, false);
//                holder = new SearchResultArticleconHolder(context, view);
//                break;
            case NEWS_ITEM:
            case PROGRAMME_ITEM:
                view = LayoutInflater.from(context).inflate(R.layout.item_search_result_article_content, parent, false);
                holder = new SearchResultArticleconHolder(context, view);
                break;
            case SPECIAL_ITEM:
                view = LayoutInflater.from(context).inflate(R.layout.item_search_result_article_content, parent, false);
                holder = new SearchResultTopicHolder(context, view);
                holder.setInternalClick(itemInternalClick);
                break;
            case LIVE_ITEM:
                view = LayoutInflater.from(context).inflate(R.layout.item_live_search, parent, false);
                holder = new SearchResultLiveHolder(context, view);
                holder.setInternalClick(itemInternalClick);
                break;
            case ANCHOR_ITEM:
                view = LayoutInflater.from(context).inflate(R.layout.item_anchor_search_file, parent, false);
                holder = new SearchResultAnchorHolder(context, view);
                holder.setInternalClick(itemInternalClick);
                break;
        }
        return holder;
    }

    @Override
    public int getItemViewType(int position) {
//        return data.get(position).getDataViewType();
        IListShowData item = data.get(position);
        if (item instanceof NewsItem) {
            return NEWS_ITEM;
        } else if (item instanceof TopicItem) {
            return SPECIAL_ITEM;
        } else if (item instanceof LiveItem) {
            return LIVE_ITEM;
        } else if (item instanceof FProgram) {
            return PROGRAMME_ITEM;
        } else if (item instanceof AFileItem) {
            return ANCHOR_ITEM;
        }
        return 0;
    }

    @Override
    public void onBindViewHolder(BaseSearchReultHolder<IListShowData> holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.setItemMode(position == getItemCount() - 1 ? BaseAnchorHolder.ITEMMODE_LAST : BaseAnchorHolder.ITEMMODE_NORMAL);
    }
}
